package com.example.casper.debugapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class ImageViewMainActivity extends AppCompatActivity {
    private Button ButtonPrevious, ButtonNext;
    private ImageView ImageViewFunny;

    private int[] imageIDArray = {R.drawable.funny_1, R.drawable.funny_2
            , R.drawable.funny_3, R.drawable.funny_4, R.drawable.funny_5
            , R.drawable.funny_6
    };
    private int imageIDArrayCurrentIndex;

    public ImageViewMainActivity() {
        imageIDArrayCurrentIndex = 0;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_view_main);

        ButtonPrevious = (Button)findViewById(R.id.button_previous);
        ButtonNext = (Button) findViewById(R.id.buttonHelloEn);
        ImageViewFunny = (ImageView)findViewById(R.id.image_view_funny);

        ButtonPrevious.setOnClickListener(new MyButtonClickListener());
        if(null==ButtonNext){
            Log.d("test", "buttonTest is null");
        }
        ButtonNext.setOnClickListener(new MyButtonClickListener());

    }

    private class MyButtonClickListener implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            if (view == ButtonNext) {
                imageIDArrayCurrentIndex ++;
                if(imageIDArrayCurrentIndex>=imageIDArray.length)imageIDArrayCurrentIndex = 1;
            } else {
                imageIDArrayCurrentIndex --;
                if(imageIDArrayCurrentIndex<0)imageIDArrayCurrentIndex=imageIDArray.length+1;
            }

            ImageViewFunny.setImageResource(imageIDArray[imageIDArrayCurrentIndex]);
        }
    }
}